﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Phong_CTSV
{
    public partial class ProfilePage : System.Web.UI.Page
    {
        QuerrySQL querry = new QuerrySQL();
        protected void Page_Load(object sender, EventArgs e)
        {
            pnAdminUser.Visible = false;
            pnNormalUser.Visible = false;
            listbox.Visible = false;
            if (Session["userName"] == null)
            {
                Response.Redirect("~/LoginPage.aspx");
            }
            listbox.Visible = false;
            if (Session["userName"] != null)
            {
                lbtnUserName.Text = Session["userName"].ToString();
                if (querry.Select_RoleID(lbtnUserName.Text) == 1)
                {
                    pnAdminUser.Visible = true;
                    pnNormalUser.Visible = false;
                    listbox.Visible = true;
                    var forms = querry.Select_AllForm();
                    List<CheckBox> list = new List<CheckBox>();
                    foreach (var item in forms)
                    {
                        listbox.Controls.Add(new LiteralControl("<br/>"));
                        CheckBox checkBox = new CheckBox();
                        checkBox.CheckedChanged += new EventHandler(checkBox_CheckedChanged);
                        checkBox.ID = item.Id.ToString();
                        checkBox.Checked = (bool)item.IsChange;
                        checkBox.Text = item.Name + " : " + item.Decription;
                        checkBox.AutoPostBack = true;
                        listbox.Controls.Add(checkBox);
                      
                    }
                }
                else
                {
                    pnAdminUser.Visible = false;
                    pnNormalUser.Visible = true;
                }
            }
        }
        void checkBox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox check = (CheckBox)sender;
            // string t = "Bảng";
            querry.UpdateFormIsChange("Bảng " + check.ID, check.Checked);
            var uni = querry.Select_AllUniversity();
            for (int i = 1; i < uni.Count; i++)
            {
                querry.Insert_Data_ByColumn("Bảng " + check.ID, uni[i].Name, System.DateTime.Now.Year);
            }
        }
              
        
        // changePass linkbutton click.
        protected void lbtnChangePass_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ChangePassPage.aspx");
        }
        protected void lbtnChangePassAdmin_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/ChangePassPage.aspx");
        }
        protected void lbtnAddNewUser_Click(object sender, EventArgs e)
        {
            Session["addUser"] = "addUser";
            Response.Redirect("~/RegistPage.aspx");
        }
        protected void lbtnUserName_Click(object sender, EventArgs e)
        {
            if (lbtnUserName.Text == "Khách")
            {
                Response.Redirect("~/LoginPage.aspx");    
            }
            else
                Response.Redirect("~/ProfilePage.aspx");
        }
        protected void lbtnUserManage_Click(object sender, EventArgs e)
        {
            Session["removeUser"] = "removeUser";
             Response.Redirect("~/DeleteAccount.aspx");
        }
        protected void lbtnAddUniversity_Click(object sender, EventArgs e)
        {
            Session["addUni"] = "addUni";
            Response.Redirect("~/RegistPage.aspx");
        }
    }
}
